<template>
	<view class="container">
		<u-navbar :bgColor="'transparent'" :titleStyle="{color: '#fff'}" title="个人信息" leftIconSize="30" :autoBack="true"
			leftIconColor="#ffffff">
		</u-navbar>
		<img class="topbg"
			src="https://img2.baidu.com/it/u=2295157616,2033848066&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" alt="" />
		<!-- 个人信息卡片 -->
		<view class="info-card">
			<!-- 头像区域 -->
			<view class="avatar-container">
				<image class="avatar"
					src="https://img2.baidu.com/it/u=2925226694,390810694&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
					mode="aspectFill"></image>
				<view class="upload-btn" @click="chooseAvatar">
					<u-icon name="camera" color="#333" size="34"></u-icon>
				</view>
			</view>
			<!-- 信息表单 -->
			<view class="form-list">
				<!-- 昵称 -->
				<view class="form-item">
					<text class="form-label">昵称</text>
					<input class="form-input" v-model="userInfo.nickname" placeholder="请输入昵称" maxlength="12" />
				</view>

				<!-- 性别 -->
				<view class="form-item">
					<text class="form-label">性别</text>
					<picker class="form-picker" :range="genderList" @change="onGenderChange" :value="genderIndex">
						<view class="picker-value">
							{{ userInfo.gender || '请选择性别' }}
							<text class="iconfont icon-arrow-right"></text>
						</view>
					</picker>
				</view>

				<!-- 生日 -->
				<view class="form-item">
					<text class="form-label">生日</text>
					<picker class="form-picker" mode="date" @change="onBirthdayChange" :value="userInfo.birthday">
						<view class="picker-value">
							{{ userInfo.birthday || '请选择生日' }}
							<text class="iconfont icon-arrow-right"></text>
						</view>
					</picker>
				</view>

				<!-- 个性签名 -->
				<view class="form-item2">
					<text class="form-label">签名</text>
					<textarea class="form-textarea" v-model="userInfo.signature" placeholder="写点什么吧..."
						maxlength="30" />
				</view>
			</view>

			<!-- 保存按钮 -->
			<button class="save-btn" @click="handleSave">保存信息</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 用户信息
				userInfo: {
					nickname: '彩虹小白马',
					gender: '男',
					birthday: '2000-06-05',
					signature: '躺平摆烂第一名'
				},
				genderList: ['男', '女'],
				genderIndex: 0
			}
		},
		methods: {
			chooseAvatar() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						// 这里处理头像上传逻辑
						console.log('头像选择成功', res)
					}
				})
			},
			onGenderChange(e) {
				this.genderIndex = e.detail.value
				this.userInfo.gender = this.genderList[this.genderIndex]
			},
			onBirthdayChange(e) {
				this.userInfo.birthday = e.detail.value
			},
			handleSave() {
				// 这里添加保存逻辑
				console.log('保存信息', this.userInfo)
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 容器样式 */
	.container {
		background: #fff;

	}

	/* 信息卡片样式 */
	.info-card {
		width: 100%;
		background: #ffffff;
		border-radius: 30px;
		padding: 20px 30px;
		box-sizing: border-box;
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
		background-color: rgba(255, 255, 255, 0.9);
		position: absolute;
		top: 100px;
	}

	/* 头像区域 */
	.avatar-container {
		position: relative;
		width: 160rpx;
		height: 160rpx;
		margin: 0 auto 60rpx;

		.avatar {
			width: 100%;
			height: 100%;
			border-radius: 50%;
			border: 4rpx dashed #e9e9e9;
		}

		.upload-btn {
			position: absolute;
			right: -20rpx;
			bottom: -20rpx;
			width: 60rpx;
			height: 60rpx;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			background: #fff;

			.iconfont {
				color: white;
				font-size: 28rpx;
			}
		}
	}

	/* 表单样式 */
	.form-list {
		margin-bottom: 80rpx;
	}

	.form-item2 {
		display: flex;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #f0f0f0;

		&:last-child {
			border-bottom: none;
		}

		.form-label {
			width: 140rpx;
			color: #666;
			font-size: 30rpx;
			margin-right: 20rpx;
			text-align: right;
		}

		.form-input {
			flex: 1;
			font-size: 32rpx;
			color: #333;
		}

		.form-picker {
			flex: 1;

			.picker-value {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #999;
				font-size: 32rpx;

				.iconfont {
					color: #999;
					font-size: 28rpx;
					margin-left: 20rpx;
				}
			}
		}

		.form-textarea {
			flex: 1;
			font-size: 32rpx;
			color: #333;
			min-height: 120rpx;
			line-height: 1.6;
			border: 1px solid #b5b5b5;
			padding: 0 10px;
			box-sizing: border-box;
		}

	}

	.form-item {
		display: flex;
		align-items: center;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #f0f0f0;

		&:last-child {
			border-bottom: none;
		}

		.form-label {
			width: 140rpx;
			color: #666;
			font-size: 30rpx;
			margin-right: 20rpx;
			text-align: right;
		}

		.form-input {
			flex: 1;
			font-size: 32rpx;
			color: #333;
		}

		.form-picker {
			flex: 1;

			.picker-value {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #999;
				font-size: 32rpx;

				.iconfont {
					color: #999;
					font-size: 28rpx;
					margin-left: 20rpx;
				}
			}
		}

		.form-textarea {
			flex: 1;
			font-size: 32rpx;
			color: #333;
			min-height: 120rpx;
			line-height: 1.6;
		}
	}

	/* 保存按钮 */
	.save-btn {
		background: linear-gradient(45deg, #007AFF, #005BFF);
		color: white;
		border-radius: 50rpx;
		font-size: 34rpx;
		height: 90rpx;
		line-height: 90rpx;
		box-shadow: 0 10rpx 20rpx rgba(0, 122, 255, 0.2);

		&::after {
			border: none;
		}
	}

	.topbg {
		width: 100%;
		height: 300px;
		background-size: 100%;
	}

	$u-navbar-title-color: #fff;
</style>